//
//  UIBarButtonItem+Category.swift
//  ZSWeibo
//
//  Created by zsj1992 on 16/4/8.
//  Copyright © 2016年 ichange. All rights reserved.
//

/**
*  UIBarButtonItem的分类
*/
import UIKit

extension UIBarButtonItem {

    //初始化方法

    class func creatItem(imageName:String?=nil,target:AnyObject?,action:Selector,title:String?=nil)->UIBarButtonItem{
    
        let btn = UIButton()
        

        
        if let img = imageName{
        
        btn.setImage(UIImage(named: img), forState: .Normal)
        btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
        
        }
        
        
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.titleLabel?.font = UIFont.systemFontOfSize(16)
        btn.sizeToFit()

        let item = UIBarButtonItem(customView: btn)
        
        return item
        
    }
}

































